package com.lhamacorp.lhamageo.ws;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;

import org.json.JSONException;
import org.json.JSONObject;

@Path("/palindromo")
public class PalindromoService {

	@Path("{p}")
	@GET
	@Produces("application/json")
	public Response isPalindromo(@PathParam("p") String palavra)
			throws JSONException {

		JSONObject jsonObject = new JSONObject();
		jsonObject.put("palavra", palavra);

		String inverso = "";
		Boolean isPalindromo;

		for (int x = palavra.length() - 1; x >= 0; x--) {
			inverso += palavra.charAt(x);
		}

		if (inverso.equals(palavra)) {
			isPalindromo = true;
		} else {
			isPalindromo = false;
		}

		jsonObject.put("isPalindromo", isPalindromo);
		
		String result = jsonObject.toString();
		return Response.status(200).entity(result).build();
	}

}